import {WindowContent} from "../../framework/dialog/WindowContent";
import {WindowName} from "../../framework/reflect/WindowName";
import {SubContextView} from "../comp/SubContextView";
import {shareUtil} from "../../framework/wx/ShareUtil";
import {logger} from "../third-scripts/game_sdk/Logger";

const {ccclass, property} = cc._decorator;

@ccclass
@WindowName("FriendRankDialog")
export default class FriendRankDialog extends WindowContent {

    @property(SubContextView)
    private rankView: SubContextView = null;

    @property(cc.Node)
    private pageLeftBtn: cc.Node = null;

    @property(cc.Node)
    private pageRightBtn: cc.Node = null;

    @property(cc.Node)
    private shareBtn: cc.Node = null;

    @property(cc.Node)
    private closeBtn: cc.Node = null;

    public onShow() {
        this.setClickListener(this.pageLeftBtn, this.pageLeftClick);
        this.setClickListener(this.pageRightBtn, this.pageRightClick);
        this.setClickListener(this.shareBtn, this.shareClick);
        this.setClickListener(this.closeBtn, this.onClose);
        this.window.setCancelableOutSide(false);

        logger.sendEvent("打开排行榜");
    }

    private pageLeftClick() {
        this.rankView.pageUp();
        logger.sendEvent("排行榜翻页", {up: true});
    }

    private pageRightClick() {
        this.rankView.pageDown();
        logger.sendEvent("排行榜翻页", {up: false});
    }

    private shareClick() {
        shareUtil.forceShare();
        logger.sendEvent("排行榜分享");
    }

    private onClose() {
        this.dismiss();
    }
}
